<?php
defined('IN_IXDCW') or exit('Access Denied');
require DT_CORE.'/'.MODULE_NAME.'/common.inc.php';
$catid  = isset($catid) ? intval($catid) : 0;
$bid    = isset($bid) ? intval($bid) : 0;
$page   = isset($page) ? intval($page) : 0;
$areaid = isset($areaid) ? intval($areaid) : 0;
$tableCompany      = Table::name(Table::NAME_COMPANY);
$filter['areaid'] = $areaid;
$filter['catid']  =  getgpc('catid');
$filter['bid']  =  $bid;
$maincat  = Category::relatives('store', $catid);

$areaFilter = Area::children($areaid);
if (!$areaFilter) {
	$areaFilter = Area::siblings($areaid);
}
$RANK   = AutoCategory::getCache(AutoCategory::TYPE_RANK);
$brand_tmp  = Auto::brands($RANK);

$brands = array();
foreach($brand_tmp as $k=>$v){
	$brands[$v['letter']][] = $v;
}

$condition = 'a.userid = m.userid and a.status=3 ';
$count_condition = 'status=3 ';

if ($areaid) {
	$area = Area::get($areaid);
	$condition .= ' and a.areaid in ('.$area['arrchildid'].')';
	$count_condition .= ' and areaid in ('.$area['arrchildid'].')';
}
if ($catid) {
	$cat = Category::module('store', $catid);
	$arrChilds = explode(',',$cat['arrchildid']);
	$strLike = '';
	$countLike = '';
	foreach($arrChilds as $child) {
		$strLike .= 'a.catid like "%,'.$child.',%" or ';
		$countLike .= 'catid like "%,'.$child.',%" or ';
	}
	$strLike = rtrim($strLike,'or ');
	$countLike = rtrim($countLike,'or ');
	$countLike = rtrim($countLike,'or ');
	$condition .= ' and ('. $strLike.')';
	$count_condition .= ' and ('. $countLike.')';
}
if ($bid) {
	$condition .= ' and  a.arbid  like "%,'.$bid.',%"';
	$count_condition .= ' and  arbid  like "%,'.$bid.',%"';
}

// 增加url自动生成
$buildBase     = array('catid', 'areaid', 'page');
$buildDrop     = 'page';

$total    = $db->count($table, $count_condition);

$do = new StoreModule($moduleid);

if ($total) {
	$lists=$do->getListByLogintime($condition,$count_condition);
}


include DT_INC.'/seo.inc.php';
include template('list', MODULE_NAME);
